/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.vportal.portlet.vcms.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.vportal.portlet.vcms.model.VcmsArticleType;
import com.vportal.portlet.vcms.model.VcmsArticleTypeModel;
import com.vportal.portlet.vcms.model.VcmsArticleTypeSoap;
import com.vportal.portlet.vcms.service.persistence.VcmsArticleTypePK;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.List;

/**
 * The base model implementation for the VcmsArticleType service. Represents a row in the &quot;VcmsArticleType&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.vportal.portlet.vcms.model.VcmsArticleTypeModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link VcmsArticleTypeImpl}.
 * </p>
 *
 * @author hai
 * @see VcmsArticleTypeImpl
 * @see com.vportal.portlet.vcms.model.VcmsArticleType
 * @see com.vportal.portlet.vcms.model.VcmsArticleTypeModel
 * @generated
 */
@JSON(strict = true)
public class VcmsArticleTypeModelImpl extends BaseModelImpl<VcmsArticleType>
	implements VcmsArticleTypeModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a vcms article type model instance should use the {@link com.vportal.portlet.vcms.model.VcmsArticleType} interface instead.
	 */
	public static final String TABLE_NAME = "VcmsArticleType";
	public static final Object[][] TABLE_COLUMNS = {
			{ "typeId", Types.BIGINT },
			{ "articleId", Types.VARCHAR },
			{ "position", Types.BIGINT }
		};
	public static final String TABLE_SQL_CREATE = "create table VcmsArticleType (typeId LONG not null,articleId VARCHAR(75) not null,position LONG,primary key (typeId, articleId))";
	public static final String TABLE_SQL_DROP = "drop table VcmsArticleType";
	public static final String ORDER_BY_JPQL = " ORDER BY vcmsArticleType.position ASC";
	public static final String ORDER_BY_SQL = " ORDER BY VcmsArticleType.position ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.vportal.portlet.vcms.model.VcmsArticleType"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.vportal.portlet.vcms.model.VcmsArticleType"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.vportal.portlet.vcms.model.VcmsArticleType"),
			true);
	public static long ARTICLEID_COLUMN_BITMASK = 1L;
	public static long TYPEID_COLUMN_BITMASK = 2L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static VcmsArticleType toModel(VcmsArticleTypeSoap soapModel) {
		VcmsArticleType model = new VcmsArticleTypeImpl();

		model.setTypeId(soapModel.getTypeId());
		model.setArticleId(soapModel.getArticleId());
		model.setPosition(soapModel.getPosition());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<VcmsArticleType> toModels(
		VcmsArticleTypeSoap[] soapModels) {
		List<VcmsArticleType> models = new ArrayList<VcmsArticleType>(soapModels.length);

		for (VcmsArticleTypeSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.vportal.portlet.vcms.model.VcmsArticleType"));

	public VcmsArticleTypeModelImpl() {
	}

	public VcmsArticleTypePK getPrimaryKey() {
		return new VcmsArticleTypePK(_typeId, _articleId);
	}

	public void setPrimaryKey(VcmsArticleTypePK primaryKey) {
		setTypeId(primaryKey.typeId);
		setArticleId(primaryKey.articleId);
	}

	public Serializable getPrimaryKeyObj() {
		return new VcmsArticleTypePK(_typeId, _articleId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey((VcmsArticleTypePK)primaryKeyObj);
	}

	public Class<?> getModelClass() {
		return VcmsArticleType.class;
	}

	public String getModelClassName() {
		return VcmsArticleType.class.getName();
	}

	@JSON
	public long getTypeId() {
		return _typeId;
	}

	public void setTypeId(long typeId) {
		_columnBitmask |= TYPEID_COLUMN_BITMASK;

		if (!_setOriginalTypeId) {
			_setOriginalTypeId = true;

			_originalTypeId = _typeId;
		}

		_typeId = typeId;
	}

	public long getOriginalTypeId() {
		return _originalTypeId;
	}

	@JSON
	public String getArticleId() {
		if (_articleId == null) {
			return StringPool.BLANK;
		}
		else {
			return _articleId;
		}
	}

	public void setArticleId(String articleId) {
		_columnBitmask |= ARTICLEID_COLUMN_BITMASK;

		if (_originalArticleId == null) {
			_originalArticleId = _articleId;
		}

		_articleId = articleId;
	}

	public String getOriginalArticleId() {
		return GetterUtil.getString(_originalArticleId);
	}

	@JSON
	public long getPosition() {
		return _position;
	}

	public void setPosition(long position) {
		_columnBitmask = -1L;

		_position = position;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public VcmsArticleType toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (VcmsArticleType)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		VcmsArticleTypeImpl vcmsArticleTypeImpl = new VcmsArticleTypeImpl();

		vcmsArticleTypeImpl.setTypeId(getTypeId());
		vcmsArticleTypeImpl.setArticleId(getArticleId());
		vcmsArticleTypeImpl.setPosition(getPosition());

		vcmsArticleTypeImpl.resetOriginalValues();

		return vcmsArticleTypeImpl;
	}

	public int compareTo(VcmsArticleType vcmsArticleType) {
		int value = 0;

		if (getPosition() < vcmsArticleType.getPosition()) {
			value = -1;
		}
		else if (getPosition() > vcmsArticleType.getPosition()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		VcmsArticleType vcmsArticleType = null;

		try {
			vcmsArticleType = (VcmsArticleType)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		VcmsArticleTypePK primaryKey = vcmsArticleType.getPrimaryKey();

		if (getPrimaryKey().equals(primaryKey)) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return getPrimaryKey().hashCode();
	}

	@Override
	public void resetOriginalValues() {
		VcmsArticleTypeModelImpl vcmsArticleTypeModelImpl = this;

		vcmsArticleTypeModelImpl._originalTypeId = vcmsArticleTypeModelImpl._typeId;

		vcmsArticleTypeModelImpl._setOriginalTypeId = false;

		vcmsArticleTypeModelImpl._originalArticleId = vcmsArticleTypeModelImpl._articleId;

		vcmsArticleTypeModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<VcmsArticleType> toCacheModel() {
		VcmsArticleTypeCacheModel vcmsArticleTypeCacheModel = new VcmsArticleTypeCacheModel();

		vcmsArticleTypeCacheModel.typeId = getTypeId();

		vcmsArticleTypeCacheModel.articleId = getArticleId();

		String articleId = vcmsArticleTypeCacheModel.articleId;

		if ((articleId != null) && (articleId.length() == 0)) {
			vcmsArticleTypeCacheModel.articleId = null;
		}

		vcmsArticleTypeCacheModel.position = getPosition();

		return vcmsArticleTypeCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{typeId=");
		sb.append(getTypeId());
		sb.append(", articleId=");
		sb.append(getArticleId());
		sb.append(", position=");
		sb.append(getPosition());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append("com.vportal.portlet.vcms.model.VcmsArticleType");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>typeId</column-name><column-value><![CDATA[");
		sb.append(getTypeId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>articleId</column-name><column-value><![CDATA[");
		sb.append(getArticleId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>position</column-name><column-value><![CDATA[");
		sb.append(getPosition());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = VcmsArticleType.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			VcmsArticleType.class
		};
	private long _typeId;
	private long _originalTypeId;
	private boolean _setOriginalTypeId;
	private String _articleId;
	private String _originalArticleId;
	private long _position;
	private long _columnBitmask;
	private VcmsArticleType _escapedModelProxy;
}